package com.share.service;

import com.share.dao.UserDao;
import com.share.domain.User;
import com.share.exception.LoginException;
import com.util.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.share.dao.BaseDao;

/**
 * @author caifan
 *
 * 2015年3月25日
 */
@Service
public class UserService {

	@Autowired
    UserDao userDao;
	
	@Autowired
	BaseDao baseDao;

	public User queryLoginByUsername(String username) {
		return userDao.loginByUsername(username);
	}
	
	public User queryLogin(String username, String password) throws  LoginException {
//		password = MD5Utils.md5(password);
		User user = userDao.loginByUsername(username);
		if (null == user) {
			return null;
		}
		if (password.equals(user.getPassword())) {
			return user;
		} else {
			throw new LoginException("用户名密码错误！");
		}
	}

	
	/*public User queryLogin(String username) {
		String sql = "select * from user where username=?";
		Map<String, Object> query = userDao.loginQuery(sql,username);
		User user = new User();
		if(query != null && query.size() > 0) {
			if(query.get("id") != null) {
				user.setId(Integer.parseInt(query.get("id").toString()));
			}
			if(query.get("username") != null) {
				user.setUsername(query.get("username").toString());
			}
			if(query.get("password") != null) {
				user.setPassword(query.get("password").toString());
			}
			if(query.get("realname") != null) {
				user.setRealname(query.get("realname").toString());
			}
			if(query.get("email") != null) {
				user.setEmail(query.get("email").toString());
			}
			if(query.get("phone") != null) {
				user.setPhone(query.get("phone").toString());
			}
			
		}
		return user;
	}*/
}
